package com.fg.pro.trade.controller;

import cn.hutool.core.util.StrUtil;
import com.fg.pro.model.reponse.ResponseResult;
import com.fg.pro.model.trade.dto.SimulationStrDto;
import com.fg.pro.trade.entity.TradeGoods;
import com.fg.pro.trade.service.TradeCustomerService;
import com.fg.pro.trade.service.TradeGoodsService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@Tag(name = "tradeCommon", description = "贸易公共接口-全部开放")
@RestController
@RequestMapping("tradeCommon")
public class TradeCommonController {

    @Resource
    private TradeCustomerService tradeCustomerService;
    @Resource
    private TradeGoodsService tradeGoodsService;

    @Operation(summary = "获取客户路线", description = "")
    @GetMapping("/getCustomerLine")
    public ResponseResult getCustomerLine() {
        List<SimulationStrDto> list = tradeCustomerService.query().groupBy("customer_route")
                .list()
                .stream()
                .filter(item -> {
                    return StrUtil.isNotEmpty(item.getCustomerRoute());
                })
                .map(item -> {
                    SimulationStrDto simulationStrDto = new SimulationStrDto();
                    simulationStrDto.setValue(item.getCustomerRoute());
                    return simulationStrDto;
                })
                .collect(Collectors.toList());
        return ResponseResult.okResult(list);
    }

    @Operation(summary = "获取商品信息", description = "商品名称")
    @GetMapping("/getGoods")
    public ResponseResult getGoods(@RequestParam(required = false)String goodsName) {
        List<TradeGoods> list = tradeGoodsService.query().like(StrUtil.isNotBlank(goodsName), "goods_name", goodsName).list();
        return ResponseResult.okResult(list);
    }


}
